from .base import Base
from .common import CommonMixin
from sqlalchemy import String, Integer, Column, SmallInteger, text
from sqlalchemy.orm import relationship


class Resource(Base, CommonMixin):
    __tablename__ = 'resource'

    id = Column(Integer, primary_key=True, comment='主键ID', autoincrement=True)
    name = Column(String(32), comment="资源名称")
    level = Column(SmallInteger, server_default=text('0'), comment="层级: 0 目录 1 菜单 2 权限")
    pid = Column(String(64), comment="父节点id")
    icon = Column(String(64), comment="图标")
    menu_url = Column(String(64), comment="页面路由")
    request_url = Column(String(64), comment="请求url")
    permission_code = Column(String(32), comment="权限code")
    role_resource = relationship("RoleResource", back_populates="resource")
